package com.atguigu.guli.service.edu.controller;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Course;
import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.service.CourseService;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduser/index")
@CrossOrigin
public class IndexController {
    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @GetMapping("index")
    public R index(){
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Course::getPrice);
        wrapper.last("limit 8");
        List<Course> courseList = courseService.list(wrapper);

        LambdaQueryWrapper<Teacher> teacherLambdaQueryWrapper = new LambdaQueryWrapper<>();
       teacherLambdaQueryWrapper.orderByDesc(Teacher::getSort);
       teacherLambdaQueryWrapper.last("limit 4");

        List<Teacher> teacherList = teacherService.list(teacherLambdaQueryWrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
